package com.trover.core.http

import okhttp3.Response
import okhttp3.ResponseBody
import org.json.JSONObject

class HandleGzipResponseInterceptor : ResponseBodyInterceptor() {
    override fun intercept(response: Response, url: String, body: String): Response {
        var jsonObject: JSONObject? = null
        try {
            jsonObject = JSONObject(body)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        val contentType = response.body?.contentType()
        val responseBody = ResponseBody.create(contentType, jsonObject.toString())
        return response.newBuilder().body(responseBody).build() // 重新生成响应对象
    }
}